#include"stack.h"
void STinit(ST* st)
{
	//assert(st);
	st->a = NULL;
	st->capacity = st->top = 0;
}
void STdestroy(ST* st)
{
	assert(st);
	st->a = NULL;
	st->capacity = st->top = 0;
}
void STpush(ST* st, typedata x)
{
	assert(st);
	if (st->capacity == st->top)
	{
		int newcapacity = st->capacity == 0 ? 4 : 2*st->capacity;
		int* tmp = (typedata*)realloc(st->a, newcapacity * sizeof(typedata));
		if (tmp == NULL)
		{
			perror("realloc fail");
			return;
		}
		st->a = tmp;
		st->capacity = newcapacity;
	}
	st->a[st->top] = x;
	st->top++;
}
void STpop(ST* st)
{
	assert(st);
	assert(!STempty(st));
	st->top--;
}
typedata STtop(ST* st)
{
	assert(st);
	assert(!STempty(st));
	return st->a[st->top-1];
}
bool STempty(ST* st)
{
	assert(st);
	return st->top == 0;
}
typedata STsize(ST* st)
{
	assert(st);
	return st->top;

}